// pages/apply/find/newstudents/allstudents.js
const app = getApp()
var CONFIG = require("../../../../config/config.js");
var share = require('../../../../utils/share.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        keyword:'',
        statusarr:[{id:'',title:'全部'},{id:2,title:'已报道'},{id:1,title:'未报到'},{id:3,title:'不来'},{id:4,title:'已退费'}],
        istatus_id:'',
        title:'',
        class_id:'',
        page:0,
        arrpeoplelist:[],
        shufalse:false,
    },
    statusclick(e){
        var that = this;
        var item = e.currentTarget.dataset.item || e.target.dataset.item;
        that.setData({
            istatus_id:item.id,
            page:0
        })
        that.consStuList();
    },
    searchclick(e){
        var that = this;
        // keykown
        var keyword = e.detail.value.keykown;
        that.setData({
            keyword: keyword,
        })
        that.consStuList();
    },
    studentdecclick(e){
        var that = this;
        var item = e.currentTarget.dataset.item || e.target.dataset.item;
        wx.navigateTo({
          url: '/pages/apply/find/newstudents/studentdec?student_id='+item.student_id+'',
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var that = this;
        if (Number(app.globalData.identity)==3){
            var consult_type = 2;
        }else{
            var consult_type = 1;
        }
        if(options.title){
            var title = options.title;
        }else{
            var title = '';
        }
        if(options.type){
            var type = options.type;
        }else{
            var type = 99;
        }
        that.setData({
            consult_type:consult_type,
            class_id:options.class_id,
            title:title,
            type:type,
        })
        that.consStuList();
    },

    consStuList(){
        var that = this;
        wx.showLoading({
            title: '加载中~',
        })
        if(Number(that.data.type)==99){
            var objdata = {
                order_id:that.data.class_id,//	否	int	期次ID
                page:that.data.page,
            }
            var url = 'crmapi/user/stuCourseClass'

        }else{
            var objdata = {
                consult_type: that.data.consult_type, //1: 课程顾问 2: 学管师
                consultant_id: app.globalData.admin_id,
                from:that.data.type,//	是	string	1-执业医师 2-主治 3-技能提升
                users:that.data.keyword,
                class_id:that.data.class_id,//	否	int	期次ID
                is_report:that.data.istatus_id,//	否	int	状态:1-未报到2-已报到3-不来4-已退费
                page:Number(that.data.page)+1
            }
            var url = 'crmapi/user/consStuList'
        }
        share.wxRequest(url, objdata, function(res) {
            if (Number(res.data.errcode) == 0) {
                if(Number(that.data.type)==99){
                    var data = res.data.data;
                }else{
                    var data = res.data.data.lists;
                }
                if (Number(that.data.page) > 0) {
                    var list = that.data.arrpeoplelist.concat(data);
                } else {
                    var list = data
                }
                that.setData({
                    arrpeoplelist: list,
                })
            }
            that.setData({
                shufalse: true,
            })
            wx.hideLoading();
        })
    },



    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

   

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        var that = this;
        var page = that.data.page;
        that.setData({
            page: Number(page) + 1
        })
        that.consStuList();
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})